package hlhj.fhp.checkpoint.atys

import android.support.v7.widget.LinearLayoutManager
import com.huantansheng.easyphotos.models.puzzle.Line
import com.liaoinstan.springview.container.DefaultFooter
import com.liaoinstan.springview.container.DefaultHeader
import com.liaoinstan.springview.widget.SpringView
import hlhj.fhp.checkpoint.BaseAty
import hlhj.fhp.checkpoint.R
import hlhj.fhp.checkpoint.adp.ProblemAdp
import hlhj.fhp.checkpoint.iview.ProblemView
import hlhj.fhp.checkpoint.javaBean.ProblemBean
import hlhj.fhp.checkpoint.presenter.ProblemPresenter
import kotlinx.android.synthetic.main.lo_publist.*

/**
 * Created by Never Fear   on 2018\11\22 0022.
Never More....
 */
class ProblemAty :BaseAty<ProblemView,ProblemPresenter>(), ProblemView, SpringView.OnFreshListener {
    private var problemAdp:ProblemAdp?=null
    private val datas=ArrayList<ProblemBean.InfoBean.DataBean>()
    private var page=1
    override fun initView() {
        problemAdp= ProblemAdp(datas)
        listView.adapter=problemAdp
        listView.layoutManager=LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false)

        spView.footer=DefaultFooter(this)
        spView.header=DefaultHeader(this)
    }
    override fun logicStart() {
        presenter?.getProblem(this,page)

    }
    override fun setListener() {
        spView.setListener(this)
    }
    override fun setProblem(problemBean: ProblemBean) {
        if (page==1){
            datas.clear()
        }
        spView.onFinishFreshAndLoad()
        datas.addAll(problemBean.info.data)
        problemAdp?.notifyDataSetChanged()

    }

    override fun onLoadmore() {
        page++
        presenter?.getProblem(this,page)

    }

    override fun onRefresh() {
        page=1
        presenter?.getProblem(this,page)

    }

    override fun bindView(): ProblemView {
        return this
    }

    override fun createPresenter(): ProblemPresenter {
        return ProblemPresenter()
    }

    override val contentId: Int= R.layout.aty_problem
}